package com.lenovo.order_service.handler;


import com.lenovo.order_service.service.OrderService;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 需要在调度中心配置表达式
 * 优化方案:
 *  1.合理配置任务执行周期,不要集中在一个时间段执行
 *  2.使用线程池或者消息队列处理长时间任务,避免阻塞主线程
 *  3.任务失败或超时时,发送告警通知
 *  4.设置重试机制,避免由于偶发性错误导致任务完全失败(需要考虑事务、幂等性问题)
 */
@Component
public class OrderHandler {
    private final Logger LOGGER = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private OrderService orderService;


    @XxlJob(value = "cleanPendingOrder")
    public void cleanPendingOrder() {
        orderService.cleanPendingOrder();
    }

    @XxlJob(value = "countHourlyAmount")
    public void countHourlyAmount() {
        orderService.countHourlyAmount();
    }
}
